﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using CRMS.Models;

namespace CRMS.Views.SelStudy
{
    public partial class frmFreeClassroomQuery : Form
    {
        private BuildingRep buidingRep = new BuildingRep();
        private ClassRoomRep classRep = new ClassRoomRep();
        public frmFreeClassroomQuery()
        {
            InitializeComponent();
        }

        private void frmFreeClassroomQuery_Load(object sender, EventArgs e)
        {
            cbBuilding.DataSource = buidingRep.GetBuildings();
            cbBuilding.DisplayMember = "TeachingBuildingName";
            cbBuilding.ValueMember = "TeachingBuildingId";
            cbWeekday.Items.AddRange(new object[] { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天" });
            cbWeekday.SelectedIndex = 1;
            cbPeriod.Items.AddRange(new object[] { "一、二", "一、二、三", "四、五", "三、四、五", "六、七、八", "六、七、八、九" });
            cbPeriod.SelectedIndex = 1;
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource =
                classRep.getFreeClassRoom(((TeachingBuilding)cbBuilding.Items[cbBuilding.SelectedIndex]).TeachingBuildingId,
                cbWeekday.Text.Trim(), cbPeriod.Text.Trim());
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value == null)
            {
                return;
            }
            else
            {
                txtBuildingName.Text = dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value.ToString();
                txtRoomID.Text = dataGridView1[1, dataGridView1.CurrentCell.RowIndex].Value.ToString();
                txtWeekday.Text = dataGridView1[2, dataGridView1.CurrentCell.RowIndex].Value.ToString();
                txtPeriod.Text = dataGridView1[3, dataGridView1.CurrentCell.RowIndex].Value.ToString();
            }
        }
    }
}
